package com.example.back.Config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/*
    配置跨域，后端
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//允许全部方法
                .allowedOriginPatterns("*")
                .allowedMethods("POST", "GET", "PATCH", "DELETE","OPTIONS")//只使用了这五个method，其他的一概拦截
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}
